package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 调拨单状态
 *
 * @author long.rao
 * @version v1.0
 * @date 2019/6/5 15:15
 * @since v1.0
 */
@Getter
public enum TransferStatusEnum {
    WAIT_OUT_INSTOCK(1, "enum.transferStatus.name.wait_out_instock", "waitOutInstock"),


    ALREADY_OUT_INSTOCK(2, "enum.transferStatus.name.already_out_instock", "alreadyOutInstock"),


    UNKNOWN(404, "enum.transferStatus.name.unknown", ""),
    ;

    private Integer code;
    private String name;
    private String attr;

    TransferStatusEnum(Integer code, String name, String attr) {
        this.code = code;
        this.name = name;
        this.attr = attr;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     *
     * @return TransferStatusEnum
     */
    public static TransferStatusEnum getByCode(Integer code) {
        for (TransferStatusEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
